<template>
  <div>
 
    <div class="container">

        <div class="item12">

            <div class="item1">
                <mymenu></mymenu>
            </div>

            <div class="item2">
                <p>登录</p>
                <van-field v-model="email" label="用户邮箱" placeholder="请输入用户邮箱"/>
                <van-field v-model="password" type="password" label="用户密码" placeholder="请输入用户密码"/>
                <van-button type="primary" @click="submit" size="small">登录</van-button>&emsp;&emsp;
                <van-button color="pink" @click="gitee" size="small">giett登录</van-button>&emsp;&emsp;
                <van-button color="pink" @click="blog" size="small">微博登录</van-button>
                
            </div>


        </div>

    </div>

  </div>
</template>

<script>
// 导入子组件
import { time } from 'console';
import mymenu from '../components/menu.vue'

export default {
    
 data() {
    return {
        // 设置表单数据
      email:'',
      password:'',
    }



 

  },
  
  components:{
    mymenu
  },
  methods:{
    gitee:function(){
        // window.location.href='https://gitee.com/oauth/authorize?client_id=f04e0838f43bfec41c508be48514a06c9f2a9238388f19aa922debe3bb151e40&redirect_uri=http://localhost:8000/gitee_back/&response_type=code'
        this.myaxios(this.baseURL + 'gitee_back/','post').then(resp=>{
            console.log('获取gitee登录url',resp)
            if(resp.errcode==0){
                var url = resp.url
                window.location.href = url

            }
        })
    },
    blog:function(){
        // window.location.href='https://api.weibo.com/oauth2/authorize?client_id=3440988304&response_type=code&redirect_uri=http://127.0.0.1:8000/weibo_back/'
        this.myaxios(this.baseURL + 'weibo_back/','post').then(resp=>{
            console.log('获取微博登录url',resp)
            if(resp.errcode==0){
                var url = resp.url
                window.location.href = url

            }
        })
    },

    submit:function(){
        if(this.email == ''){
            this.$toast.fail('邮箱不能为空');
            return false
        }

        if(this.password == ''){
            this.$toast.fail('密码不能为空');
            return false
        }


        // 发起请求
        this.myaxios(this.baseURL+'user/login','get',{email:this.email,password:this.password}).then(resp=>{
            console.log('登录的响应',resp)
            if(resp.errcode == 0){
                //存储用户信息
                localStorage.setItem('token',resp.token)
                localStorage.setItem('email',resp.email)

                this.$toast.success(resp.msg)
                window.location.href = '/'
                // this.$router.push('/')
            }
            else if(resp.errcode == 402){
                this.$toast.fail(resp.msg)
                // this.$toast.loading({      // 加载提示
                // message: '跳转激活页面',
                // forbidClick: true,
                // loadingType: 'spinner',
                // });
                window.location.href = '/active'
                // this.$router.push('/active')
            }
            else{
                this.$toast.fail(resp.msg)
            }
        })

    },
  

  },
  mounted(){
    
  },
  created(){

    

  }

}
</script>


<style scoped>
@import url('../assets/style.css');


</style>

